﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio;
using System.Runtime.InteropServices;
using Antlr.Runtime;

namespace FixtureHighlighter
{
    [Guid(FixtureContstants.LanguageServiceGuid)]
    public class FixtureLanguageService : LanguageService
    {
        LanguagePreferences _preferences;

        public FixtureLanguageService()
        {
        }

        public override LanguagePreferences GetLanguagePreferences()
        {
            if (_preferences == null)
            {
                _preferences = new LanguagePreferences(Site, GetType().GUID, Name);
                _preferences.Init();
            }

            return _preferences;
        }


        public override Source CreateSource(IVsTextLines buffer)
        {
            return new FixtureSource(this, buffer, GetColorizer(buffer));
        }


        public override IScanner GetScanner(IVsTextLines buffer)
        {
            return new FixtureScanner(this, buffer);
        }

        public override AuthoringScope ParseSource(ParseRequest req)
        {
            FixtureSource source = (FixtureSource)GetSource(req.FileName);
            bool result = false;

            if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex
                || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine)
            {
                
            }

            switch (req.Reason)
            {
                case ParseReason.Check:
                case ParseReason.HighlightBraces:
                case ParseReason.MatchBraces:
                case ParseReason.MemberSelectAndHighlightBraces:
                default:
                    break;
            }

            return new FixtureAuthoringScope(source.ParseResult);
        }

        public override string GetFormatFilterList()
        {
            return "Fixture File (*.fix)\n*.fix";
        }

        public override string Name
        {
            get
            {
                return FixtureContstants.LanguageName;
            }
        }
    }
}
